package key;

// GenerateKey.java

import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
/**
 * 生成钥匙文件
 * @author Administrator
 *
 */
public class GenerateKey
{
  static public void main( String args[] ) throws Exception {
    String keyFilename = "key.data";//args[0];
    String algorithm = "DES";

    // 生成密匙
    SecureRandom sr = new SecureRandom();
    KeyGenerator kg = KeyGenerator.getInstance( algorithm );
    kg.init( sr );
    SecretKey key = kg.generateKey();

    // 把密匙数据保存到文件
    Util.writeFile( keyFilename, key.getEncoded() );
  }
}

